package com.jhclothing.web.controller.statistic;

import com.jhclothing.common.core.controller.BaseController;
import com.jhclothing.common.core.page.TableDataInfo;
import com.jhclothing.common.enums.StatisticType;
import com.jhclothing.inbound.service.IClothingInboundService;
import com.jhclothing.inbound.service.IFabricInboundService;
import com.jhclothing.outbound.service.IClothingOutboundService;
import com.jhclothing.outbound.service.IFabricOutboundService;
import com.jhclothing.product.vo.StatisticInOutVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 统计出入库信息
 */
@RestController
@RequestMapping("/statistic/inout")
public class StatisticInOutController extends BaseController {
    @Autowired
    private IFabricInboundService fabricInboundService;
    @Autowired
    private IFabricOutboundService fabricOutboundService;
    @Autowired
    private IClothingInboundService clothingInboundService;
    @Autowired
    private IClothingOutboundService clothingOutboundService;

    /**
     * 统计出入库信息
     */
    @PreAuthorize("@ss.hasPermi('statistic:inout:list')")
    @GetMapping("/list")
    public TableDataInfo list(StatisticInOutVo statisticInOutVo) {
        startPage();
        List<StatisticInOutVo> list = new ArrayList<>();
        if (StatisticType.FABRIC_INBOUND.getCode().equals(statisticInOutVo.getStatisticType())) {
            // 默认返回布料入库信息统计列表
            list = fabricInboundService.statisticFabricInboundNum(statisticInOutVo);
            return getDataTable(list);
        }
        if (StatisticType.FABRIC_OUTBOUND.getCode().equals(statisticInOutVo.getStatisticType())) {
            list = fabricOutboundService.statisticFabricOutboundNum(statisticInOutVo);
            return getDataTable(list);
        }
        if (StatisticType.CLOTHING_INBOUND.getCode().equals(statisticInOutVo.getStatisticType())) {
            list = clothingInboundService.statisticClothingInboundNum(statisticInOutVo);
            return getDataTable(list);
        }
        if (StatisticType.CLOTHING_OUTBOUND.getCode().equals(statisticInOutVo.getStatisticType())) {
            list = clothingOutboundService.statisticClothingOutboundNum(statisticInOutVo);
            return getDataTable(list);
        }
        list.addAll(fabricInboundService.statisticFabricInboundNum(statisticInOutVo));
        list.addAll(fabricOutboundService.statisticFabricOutboundNum(statisticInOutVo));
        list.addAll(clothingInboundService.statisticClothingInboundNum(statisticInOutVo));
        list.addAll(clothingOutboundService.statisticClothingOutboundNum(statisticInOutVo));
        return getDataTable(list);
    }
}
